package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.api.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理" ,tags = "channel", description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService channelService;

    /**
     * 频道列表查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @Override
    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询频道列表")
    @ApiImplicitParam(name = "dto",type ="ChannelDto",value = "查询名称")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        ResponseResult page = channelService.findByNameAndPage(dto);
        return page;
    }

    /**
     * 频道列表添加
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    @Override
    @ApiOperation(value = "添加频道信息",notes = "添加频道")
    @ApiImplicitParam(name = "adChannel",type ="AdChannel",value = "频道添加")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return channelService.insert(adChannel);
    }

    /**
     * 频道列表修改
     * @param adChannel
     * @return
     */
    @PostMapping("/update")
    @Override
    @ApiOperation(value = "修改频道信息",notes = "根据id修改频道")
    @ApiImplicitParam(name = "adChannel",type ="AdChannel",value = "频道修改")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return channelService.update(adChannel);
    }

    /**
     *频道列表删除
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    @Override
    @ApiOperation(value = "删除频道信息",notes = "根据id删除频道")
    @ApiImplicitParam(name = "id",type ="Integer",value = "频道删除")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return channelService.deleteById(id);
    }


    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
